
import 'http_exceptions.dart';
import 'response_model/response_data.dart';

class ApiResponse<T> implements Exception {
  AppException? exception;
  Status? status;

  int? errorCode;
  String? errorMsg;
  T? data;

  //数据是否真正返回成功
  bool isSuccessful() {
    return status == Status.completed && errorCode != null && errorCode == 0;
  }

  ApiResponse.completed(this.data, dynamic responseData) {
    status = Status.completed;
    errorCode = responseData[ResponseData.errorCode];
    errorMsg = responseData[ResponseData.errorMsg];
  }

  ApiResponse.error(this.exception) : status = Status.error;

  @override
  String toString() {
    return "Status : $status \n Message : $exception \n Data : $data";
  }
}

enum Status { completed, error }
